using System;
using System.Collections.Generic;

public static class Messenger
{
	public static void AddListener(string eventType, Callback handler)
	{
		MessengerInternal.OnListenerAdding(eventType, handler);
		Messenger.eventTable[eventType] = (Callback)Delegate.Combine((Callback)Messenger.eventTable[eventType], handler);
	}

	public static void RemoveListener(string eventType, Callback handler)
	{
		MessengerInternal.OnListenerRemoving(eventType, handler);
		Messenger.eventTable[eventType] = (Callback)Delegate.Remove((Callback)Messenger.eventTable[eventType], handler);
		MessengerInternal.OnListenerRemoved(eventType);
	}

	public static void Broadcast(string eventType)
	{
		Messenger.Broadcast(eventType, MessengerInternal.DEFAULT_MODE);
	}

	public static void Broadcast(string eventType, MessengerMode mode)
	{
		MessengerInternal.OnBroadcasting(eventType, mode);
		Delegate @delegate;
		if (Messenger.eventTable.TryGetValue(eventType, out @delegate))
		{
			Callback callback = @delegate as Callback;
			if (callback == null)
			{
				throw MessengerInternal.CreateBroadcastSignatureException(eventType);
			}
			callback();
		}
	}

	private static Dictionary<string, Delegate> eventTable = MessengerInternal.eventTable;
}
